package edu.hut.bookshop.controller;

import com.github.pagehelper.PageInfo;
import edu.hut.bookshop.pojo.Business;
import edu.hut.bookshop.pojo.User;
import edu.hut.bookshop.service.BusinessService;
import edu.hut.bookshop.util.ResultCode;
import edu.hut.bookshop.util.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/bus")
public class BusinessController {

    @Autowired
    private BusinessService businessService;

    @GetMapping("/insert")
    public ResultVO insertBus(String bName, String bPasswd) {
       //先查询有没有重复
        Business business = new Business();
        business = businessService.selectBybName(bName);
        if(business==null) {
            return new ResultVO(ResultCode.SUCCESS,businessService.insertBusiness(bName,bPasswd));
        }else
        if(bName.equals(business.getbName())){
            return new ResultVO(ResultCode.FAILED2,null);
        }
            return new ResultVO(ResultCode.SUCCESS,businessService.insertBusiness(bName,bPasswd));
    }
}
